const { app, Menu, BrowserWindow, Notification } = require('electron')
const path = require('path')

function createWindow () {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  win.loadFile('index.html')
  win.setProgressBar(3)
  win.setThumbarButtons([
    {
      tooltip: 'button1',
      icon: path.join(__dirname, 'button1.png'),
      click () { console.log('button1 clicked') }
    }, {
      tooltip: 'button2',
      icon: path.join(__dirname, 'button2.png'),
      flags: ['enabled', 'dismissonclick'],
      click () { console.log('button2 clicked.') }
    }
  ])
}
function showNotification(){
  const  notification = {
    title: "Basic Notification",
    body: "Notification from the Main Process"
  }
  new Notification(notification).show()
}





const dockMenu = Menu.buildFromTemplate([
  {
    label: 'New Window',
    click () { console.log('New Window') }
  }, {
    label: 'New Window with Settings',
    submenu: [
      { label: 'Basic' },
      { label: 'Pro' }
    ]
  },
  { label: 'New Command...' }
])

app.whenReady().then(createWindow).then(showNotification).then(()=>{
  app.dock.setMenu(dockMenu)
})
app.addRecentDocument('/Users/xingxiaofei/Desktop/work.type')
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})
